﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AMS.Chess.CommonLayer
{
    public class StandardChessPieceFactory : IChessPieceFactory
    {
        public StandardChessPieceFactory() { }

        public virtual APawn CreatePawn(AChessBoard board, ChessColor color)
        {
            return new Pawn(board, color);
        }

        public virtual AKnight CreateKnight(AChessBoard board, ChessColor color)
        {
            return new Knight(board, color);
        }

        public virtual ABishop CreateBishop(AChessBoard board, ChessColor color)
        {
            return new Bishop(board, color);
        }

        public virtual ARook CreateRook(AChessBoard board, ChessColor color)
        {
            return new Rook(board, color);
        }

        public virtual AQueen CreateQueen(AChessBoard board, ChessColor color)
        {
            return new Queen(board, color);
        }

        public virtual AKing CreateKing(AChessBoard board, ChessColor color)
        {
            return new King(board, color);
        }
        
        /// <summary>
        /// Provides extensibility to allow a subclassed factory to produce other types of pieces.
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public virtual AChessPiece CreateChessPiece(Type t, AChessBoard board, ChessColor color)
        {
            if (t == typeof(King)) { return CreateKing(board, color); }
            else if (t == typeof(Queen)) { return CreateQueen(board, color); }
            else if (t == typeof(Rook)) { return CreateRook(board, color); }
            else if (t == typeof(Bishop)) { return CreateBishop(board, color); }
            else if (t == typeof(Knight)) { return CreateKnight(board, color); }
            else if (t == typeof(Pawn)) { return CreatePawn(board, color); }
            else
            {
                //return null;
                throw new InvalidOperationException("This Factory cannot produce the specified Type of AChessPiece.");
            }
        }

    }
}
